var pageii = null;
var grid = null;
$(function() {
	
	grid = lyGrid({
		pagId : 'paging',
		l_column : [ {
			colkey : "id",
			name : "操作",
			width : "55px",
			renderData : function(rowindex,data, rowdata, column) {
				if (data == 1) {
					return "";
				} else {
					return "<img class='imgbtn' title='编辑分组' src='" + rootPath + "/images/edit.png' onclick=\"editFun('"+data+"')\"/>";
				}
			}
		}, {
			colkey : "id",
			name : "id",
			renderData : function(rowindex,data, rowdata, column) {
				if (data == 1) {
					$("input[type=checkbox][value=1]").remove();
				}
				return data;
			}
		}, {
			colkey : "name",
			name : "组名"
		}],
		jsonUrl : rootPath + '/group/findByPage.shtml',
		checkbox : true,
		serNumber : false
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();// 初始化传参数
		$("input[qt=like]").each(function() {
			if ($(this).val().trim() != "") {
				searchParams[$(this).attr("name")] = "%" + $(this).val().trim() + "%";
			}
		});
		grid.setOptions({
			data : searchParams
		});
	});
	$("#addFun").click("click", function() {
		addFun();
	});
	$("#editFun").click("click", function() {
		editFun();
	});
	$("#delFun").click("click", function() {
		delFun();
	});
});
function editFun(cbox) {
	pageii = layer.open({
		title : "编辑",
		type : 2,
		area : [ "600px", "195px" ],
		content : [rootPath + '/group/editUI.shtml?id=' + cbox, 'no']
	});
}
function addFun() {
	pageii = layer.open({
		title : "新增",
		type : 2,
		area : [ "600px", "195px" ],
		content : [rootPath + '/group/addUI.shtml', 'no']
	});
}
function delFun() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/group/deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}